﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using System.Data;
using BEGDC.Utility.NHibernate;
using Castle.Services.Transaction;
using System.Collections;
using System.Xml;
using Castle.Facilities.NHibernateIntegration;

namespace BEGDC.PreContract.BLL
{
	public partial class MenuRoleMapping: IMenuRoleMapping
	{

        /// <summary>
        /// update special role information.
        /// </summary>
        [Transaction(TransactionMode.Requires)]
        public void AddMenuRole(DataTable dt)
        {
            try
            {
                BEGDC.PreContract.DAL.MenuRoleMapping.DeleteAll();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    BEGDC.PreContract.DAL.MenuRoleMapping menurole = new BEGDC.PreContract.DAL.MenuRoleMapping();
                    BEGDC.PreContract.DAL.MenuConfig menu = BEGDC.PreContract.DAL.MenuConfig.TryFind(int.Parse(dt.Rows[i]["MenuID"].ToString().Trim()));
                    BEGDC.PreContract.DAL.Role role = BEGDC.PreContract.DAL.Role.TryFind(Convert.ToInt32(dt.Rows[i]["RoleID"].ToString().Trim()));
                    menurole.MenuID = menu;
                    menurole.RoleID = role;

                    menurole.Create();

                }


            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        /// <summary>
        /// Get Menu role information by menu id.
        /// </summary>
        /// <param name="menuid">menu id</param>
        /// <returns>Employee Entity</returns>
        public DataSet GetMenuRoleByMenuId(string menuid)
        {
            DataSet ds = null;
            string strsql = string.Empty;
            using (ISession session = factory.OpenSession())
            {

                strsql = " SELECT DISTINCT a.RoleID FROM MenuRoleMapping a INNER JOIN Role b ON a.RoleID=b.RoleID WHERE  MenuID='" + menuid + "'";


                ds = DAO.ExecuteDataSet(session, strsql);

            }
            return ds;
        }


    }
}



